/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.memberView;
/**
 * 说明：
 * 订单详细
 * @Author：黄盛强
 * @Date：2012-03-26
 */
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;

import com.ruipengkj.bean.TBehavior;
import com.ruipengkj.bean.TOrder;
import com.ruipengkj.bean.TShopVisit;
import com.ruipengkj.bean.TUser;
import com.ruipengkj.commons.BuildSpringApplication;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.model.BehaviorDetailModel;
import com.ruipengkj.service.TOrderService;
import com.ruipengkj.service.TShopVisitService;
import com.ruipengkj.view.base.BaseDialog;

public class MemberBehaviorDialog extends BaseDialog {

	private static final long serialVersionUID = 1L;
	
	
	private JTable table = null;//订单Table
	private BehaviorDetailModel behaviorDetailModel;//model
	private JScrollPane tableJsp;
	private TOrderService tOrderService;
	private TShopVisitService tShopVisitService;
	private FlowLayout flowLayout;
	private TUser user=new TUser();
	
	public MemberBehaviorDialog(JDialog jd, String title, boolean b) {
		super(jd, title, b);
		tOrderService = BuildSpringApplication.getInstance().getTOrderServiceImpl();
		tShopVisitService = BuildSpringApplication.getInstance().getTShopVisitServiceImpl();
		this.setLayout(new BorderLayout());
		this.init();
		this.setSize(900, 600);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		
	}
	private void init() {
		flowLayout=new FlowLayout(FlowLayout.LEFT);
		
		behaviorDetailModel = new BehaviorDetailModel();
		table=uiFactory.createRPJTable(behaviorDetailModel, this, this, 30, JLabel.CENTER);
		tableJsp=uiFactory.createJScrollPane(table);
		//this.add(tableJsp, BorderLayout.CENTER);
		JPanel main_jp=new JPanel(new BorderLayout());
		main_jp.setBackground(Util.PANEL_COLOR);
		main_jp.add(tableJsp, BorderLayout.CENTER);
		this.add(main_jp);
	}
	
	//数据库中的数据放入list（读取数据）
	private Runnable queryBillDetail=new Runnable() {
		@Override
		public void run() {
			try {
				TOrder tOrder = new TOrder();
				tOrder.setTUser(user);
				TShopVisit tShopVisit=new TShopVisit();
				tShopVisit.setTUser(user);
				List<TOrder> tOrderList = tOrderService.findService(tOrder);
				List<TShopVisit> tShopVisitList=tShopVisitService.findService(tShopVisit);
				List<TBehavior> tBehavior = new ArrayList();
				for(int i =0;i<tOrderList.size();i++){
					tBehavior.add(tOrderList.get(i));
				}
				for(int i =0;i<tShopVisitList.size();i++){
					tBehavior.add(tShopVisitList.get(i));
				}
				
				behaviorDetailModel.setBehaviorList(tBehavior);
//				if (billDetailList != null &&  billDetailList.size()!= 0) {
//					int length = billDetailList.size();
//					for (int i = 0; i < length; ++i) {
//						//获取商品 以便查看
//						billDetailList.get(i).setCommodity(tCommodityService.getByIdService(billDetailList.get(i).getCommodityID()));
//						behaviorDetailModel.addBillDetail(billDetailList.get(i));
//					}
//				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	};
	
	public void showDialog(TUser tUserID) {
		user = tUserID;
		if (tUserID != null) {
			SwingUtilities.invokeLater(queryBillDetail);
			
		}
		this.setVisible(true);
	}
}